<template>
  <BasicModal
    v-bind="$attrs"
    @register="register"
    title="审批教师认证"
    centered
    minHeight='0'

    @ok="submit()"
  >
    <div>
      <p>是否通过[{{ formData.fname }}]的教师认证申请？</p>
    </div>
    <div style="">
      <h2>设置教师工作量：</h2>
      <BasicForm @register="registerForm"/>
    </div>
  </BasicModal>
</template>
<script lang="ts">
import {defineComponent, ref} from 'vue';
import {BasicModal, useModalInner} from '/@/components/Modal';
import {TeacherLogPass} from "/@/api/teacher/teacher";
import {message} from "ant-design-vue";
import {BasicForm, useForm} from "/@/components/Form";
import {formSchema} from "/@/views/teacher/log/schema.data";

export default defineComponent({
  components: {BasicModal, BasicForm},
  emits: ['success', 'handleReload'],
  setup(_, {emit}) {
    let formData = ref({});
    const [register, {setModalProps, closeModal}] = useModalInner(data => {
      console.log('data', data.record)
      setModalProps({confirmLoading: false});
      formData.value = data.record

      resetFields();
      setFieldsValue({
        ...data.record,
      });

    });

    const [registerForm, {resetFields, setFieldsValue, validate}] = useForm({
      labelWidth: 100,
      schemas: formSchema,
      showActionButtonGroup: false,
    });

    async function submit() {
      // setModalProps({confirmLoading: true});
      const values = await validate();

      TeacherLogPass({...formData.value, ...values}).then(res => {
        console.log('审批结果', res)
        message.success('已通过审批')
        closeModal();
        emit('success');
      }).finally(() => {
        emit('handleReload');
        closeModal();
        setModalProps({confirmLoading: false});
      })
    }

    return {
      registerForm,
      formData,
      submit,
      register,
    };
  },
});
</script>
